﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<TemplateWeb.Models.ViewModels.GroupViewModel>" %>
<script type="text/javascript">
    function ValidateUpdateRevenue() {
        var dagiaohang = document.getElementsByName("IsShipped").item(0);
        var dahuy = document.getElementsByName("IsCanceled").item(0);
        if (dagiaohang.checked && dahuy.checked) {
            alert("Khi đã giao hàng thì không được hủy đơn hàng");
            return false;
        }
        return true;
    }
</script>

<%
    var idkhachhang = ViewData["IDKhachHang"] == null ? string.Empty : ViewData["IDKhachHang"].ToString();
    var khuvuc = ViewData["KhuVuc"] == null ? string.Empty : ViewData["KhuVuc"].ToString();
    var daxacnhan = ViewData["DaXacNhan"] == null ? string.Empty : ViewData["DaXacNhan"].ToString();
    var daxacnhan_value = ViewData["DaXacNhan_Value"] == null ? string.Empty : ViewData["DaXacNhan_Value"].ToString();
    var dagiaohang = ViewData["DaGiaoHang"] == null ? string.Empty : ViewData["DaGiaoHang"].ToString();
    var dagiaohang_value = ViewData["DaGiaoHang_Value"] == null ? string.Empty : ViewData["DaGiaoHang_Value"].ToString();
    var dahuy = ViewData["DaHuy"] == null ? string.Empty : ViewData["DaHuy"].ToString();
    var dahuy_value = ViewData["DaHuy_Value"] == null ? string.Empty : ViewData["DaHuy_Value"].ToString();
%>

<div class="AdminPageText">
    List Of Orders
</div>
<% using (Html.BeginForm("TimKiem_UpdateOrders", "Admin", FormMethod.Post, new { id = "MySubmitForm", onsubmit = "return ValidateUpdateRevenue();" }))
   { %>
<table class="Grid" cellpadding="0" cellspacing="0">
    <thead>
        <tr>
            <th>
                ID
            </th>
            <th>
                Ngày đặt hàng
            </th>
            <th>
                Đã xác nhận
            </th>
            <th>
                Đã giao hàng
            </th>
            <th>
                Ngày giao hàng
            </th>
            <th>
                Hủy đơn hàng
            </th>
            <th>
            </th>
            <th>
            </th>
            <tr>
    </thead>
    <% for (int i = 0; i < Model.DonDatHangModel.GetModel.LstObjModel.Count; i++)
       {
           if (i % 2 != 0)
           {%>
    <tr class="Row" id="row-<%= Model.DonDatHangModel.GetModel.LstObjModel[i].ID %>">
        <% }
           else
           { %>
        <tr class="AlternatingRow" id="row-<%= Model.DonDatHangModel.GetModel.LstObjModel[i].ID %>">
            <% } %>
            <td>
                <span style="">
                    <%= Model.DonDatHangModel.GetModel.LstObjModel[i].ID %></span>
            </td>
            <td>
                <span style="">
                    <%= string.Format("{0:dd/MM/yyyy hh:mm:ss}", Model.DonDatHangModel.GetModel.LstObjModel[i].NgayDatHang.Value)%></span>
            </td>
            <% if (Model.DonDatHangModel.GetModel.LstObjModel[i].ID == Model.DonDatHangModel.EditModel.ID)
               { %>
            <td>
                <span style="">
                    <%= Html.CheckBox("IsVerified", Model.DonDatHangModel.GetModel.LstObjModel[i].DaXacNhan.Value )%></span>
            </td>
            <td>
                <span style="">
                    <%= Html.CheckBox("IsShipped", Model.DonDatHangModel.GetModel.LstObjModel[i].DaGiaoHang.Value )%></span>
            </td>
            <td>
                <input type="text" name="Orders_NgayGiaoHang" id="Orders_NgayGiaoHang" value="<%= Model.DonDatHangModel.GetModel.LstObjModel[i].NgayGiaoHang == null ? string.Empty : Model.DonDatHangModel.GetModel.LstObjModel[i].NgayGiaoHang.Value.ToShortDateString() %>" />
            </td>
            <td>
                <span style="">
                    <%= Html.CheckBox("IsCanceled", Model.DonDatHangModel.GetModel.LstObjModel[i].HuyDonHang.Value )%></span>
            </td>
            <td>
                <a href="#" onclick="submitForm();"><span style="color: Blue; text-decoration: underline">
                    Update</span> </a>&nbsp;
                <%= Html.Hidden("DaXacNhan", daxacnhan)%>
                <%= Html.Hidden("DaXacNhan_Value", daxacnhan_value)%>
                <%= Html.Hidden("DaGiaoHang", dagiaohang)%>
                <%= Html.Hidden("DaGiaoHang_Value", dagiaohang_value)%>
                <%= Html.Hidden("DaHuy", dahuy)%>
                <%= Html.Hidden("DaHuy_Value", dahuy_value)%>
                <%= Html.Hidden("IDKhachHang", idkhachhang)%>
                <%= Html.Hidden("KhuVuc", khuvuc)%>
                <%= Html.Hidden("Orders_ID", Model.DonDatHangModel.GetModel.LstObjModel[i].ID)%>
                <a href="../../Admin/TimKiem_CancelEditingOrders?idorder=<%= Model.DonDatHangModel.GetModel.LstObjModel[i].ID %>&idKhachHang=<%= idkhachhang %>&apdung_daxacnhan=<%= daxacnhan %>&apdung_daxacnhan_val=<%= daxacnhan_value %>&apdung_dagiaohang=<%= dagiaohang %>&apdung_dagiaohang_val=<%= dagiaohang_value %>&apdung_dahuy=<%= dahuy %>&apdung_dahuy_val=<%= dahuy_value %>&khuvuc=<%= khuvuc %>">
                    <span style="color: Blue; text-decoration: underline">Cancel</span> </a>
            </td>
            <% }
               else
               { %>
            <td>
                <span style="">
                    <%= Html.CheckBox("IsVerified2", Model.DonDatHangModel.GetModel.LstObjModel[i].DaXacNhan.Value, new { disabled = "disabled" })%></span>
            </td>
            <td>
                <span style="">
                    <%= Html.CheckBox("IsShipped2", Model.DonDatHangModel.GetModel.LstObjModel[i].DaGiaoHang.Value, new { disabled = "disabled" })%></span>
            </td>
            <td>
                <span style="">
                    <%= Model.DonDatHangModel.GetModel.LstObjModel[i].NgayGiaoHang == null ? string.Empty : string.Format("{0:dd/MM/yyyy hh:mm:ss}", Model.DonDatHangModel.GetModel.LstObjModel[i].NgayGiaoHang.Value)%></span>
            </td>
            <td>
                <span style="">
                    <%= Html.CheckBox("IsCanceled2", Model.DonDatHangModel.GetModel.LstObjModel[i].HuyDonHang.Value, new { disabled = "disabled" })%></span>
            </td>
            <td style="text-align: center">
                <a href="../../Admin/TimKiem_EditOrders?idorder=<%= Model.DonDatHangModel.GetModel.LstObjModel[i].ID %>&idKhachHang=<%= idkhachhang %>&apdung_daxacnhan=<%= daxacnhan %>&apdung_daxacnhan_val=<%= daxacnhan_value %>&apdung_dagiaohang=<%= dagiaohang %>&apdung_dagiaohang_val=<%= dagiaohang_value %>&apdung_dahuy=<%= dahuy %>&apdung_dahuy_val=<%= dahuy_value %>&khuvuc=<%= khuvuc %>">
                    <span style="color: Blue; text-decoration: underline">Edit</span> </a>
            </td>
            <% } %>
            <td style="text-align: center">
                <a href="../../Admin/TimKiem_SelectOrderDetail?idorder=<%= Model.DonDatHangModel.GetModel.LstObjModel[i].ID %>&idKhachHang=<%= idkhachhang %>&apdung_daxacnhan=<%= daxacnhan %>&apdung_daxacnhan_val=<%= daxacnhan_value %>&apdung_dagiaohang=<%= dagiaohang %>&apdung_dagiaohang_val=<%= dagiaohang_value %>&apdung_dahuy=<%= dahuy %>&apdung_dahuy_val=<%= dahuy_value %>&khuvuc=<%= khuvuc %>">
                    <span style="">Select</span> </a>
            </td>
        </tr>
        <% } %>
</table>
<% if (Model.SelectedDonDatHangModel != null)
   { %>
<%
    var total = 0.0;
    for (int i = 0; i < Model.ChiTietDonDatHangModel.GetModel.LstObjModel.Count; i++)
    {
        total += (Model.ChiTietDonDatHangModel.GetModel.LstObjModel[i].SoLuong.Value * Model.ChiTietDonDatHangModel.GetModel.LstObjModel[i].Gia.Value);
    }
%>
<br />
<br />
<span style="font-size: 18px; font-weight: bold;">Order
    <%= Model.SelectedDonDatHangModel.GetModel.LstObjModel[0].ID %></span>
<br />
<table class="AdminPageText">
    <tr>
        <td width="130" style="font-weight: bold;">
            Tổng tiền:
        </td>
        <td style="font-weight: bold; color: Red">
            <%= string.Format("{0:0,0}", total)%>
            Đ
        </td>
    </tr>
    <tr>
        <td width="130">
            Mã Khách hàng:
        </td>
        <td>
            <%= Model.SelectedDonDatHangModel.GetModel.LstObjModel[0].ID%>
        </td>
    </tr>
    <tr>
        <td width="130">
            Tên khách hàng:
        </td>
        <td>
            <%= Model.SelectedDonDatHangModel.GetModel.LstObjModel[0].NguoiDung.HoTen%>
        </td>
    </tr>
    <tr>
        <td width="130">
            Tên người nhận:
        </td>
        <td>
            <%= Model.SelectedDonDatHangModel.GetModel.LstObjModel[0].TenNguoiNhan %>
        </td>
    </tr>
    <tr>
        <td width="130">
            SĐT người nhận:
        </td>
        <td>
            <%= Model.SelectedDonDatHangModel.GetModel.LstObjModel[0].SoDienThoaiNguoiNhan %>
        </td>
    </tr>
    <tr>
        <td width="130">
            Địa chỉ người nhận:
        </td>
        <td>
            <%= Model.SelectedDonDatHangModel.GetModel.LstObjModel[0].DiaChiNguoiNhan %>
        </td>
    </tr>
    <tr>
        <td width="130">
            Ngày đặt hàng:
        </td>
        <td>
            <%= string.Format("{0:dd/MM/yyyy hh:mm:ss}", Model.SelectedDonDatHangModel.GetModel.LstObjModel[0].NgayDatHang.Value)%>
        </td>
    </tr>
    <tr>
        <td width="130">
            Đã xác nhận:
        </td>
        <td>
            <%= Model.SelectedDonDatHangModel.GetModel.LstObjModel[0].DaXacNhan.Value ? "Rồi" : "Chưa" %>
        </td>
    </tr>
    <tr>
        <td width="130">
            Đã giao hàng:
        </td>
        <td>
            <%= Model.SelectedDonDatHangModel.GetModel.LstObjModel[0].DaGiaoHang.Value ? "Rồi" : "Chưa"%>
        </td>
    </tr>
    <tr>
        <td width="130">
            Hủy đơn hàng:
        </td>
        <td>
            <%= Model.SelectedDonDatHangModel.GetModel.LstObjModel[0].HuyDonHang.Value ? "Rồi" : "Chưa"%>
        </td>
    </tr>
    <tr>
        <td width="130">
            Ngày giao hàng:
        </td>
        <td>
            <%= Model.SelectedDonDatHangModel.GetModel.LstObjModel[0].NgayGiaoHang == null ? string.Empty : string.Format("{0:dd/MM/yyyy hh:mm:ss}", Model.SelectedDonDatHangModel.GetModel.LstObjModel[0].NgayGiaoHang.Value)%>
        </td>
    </tr>
    <tr>
        <td width="130">
            Chú thích thêm:
        </td>
        <td>
            <%= Model.SelectedDonDatHangModel.GetModel.LstObjModel[0].ChuThich %>
        </td>
    </tr>
</table>
<br />
<div class="AdminPageText">
    Chi tiết đơn đặt hàng
</div>
<table class="Grid" cellpadding="0" cellspacing="0">
    <thead>
        <tr>
            <th style="text-align: center;">
                STT
            </th>
            <th style="text-align: left; padding-left: 10px;">
                Tên sách
            </th>
            <th style="text-align: center;">
                Số lượng
            </th>
            <th style="text-align: center;">
                Đơn giá
            </th>
            <tr>
    </thead>
    <% for (int i = 0; i < Model.ChiTietDonDatHangModel.GetModel.LstObjModel.Count; i++)
       {
           if (i % 2 != 0)
           {%>
    <tr class="Row" id="Tr1">
        <% }
           else
           { %>
        <tr class="AlternatingRow" id="row-<%= Model.ChiTietDonDatHangModel.GetModel.LstObjModel[i].ID %>">
            <% } %>
            <td style="text-align: center">
                <span style="">
                    <%= (i + 1) %></span>
            </td>
            <td style="text-align: left; padding-left: 10px;">
                <span style="">
                    <%= Model.ChiTietDonDatHangModel.GetModel.LstObjModel[i].Sach.TenSach %></span>
            </td>
            <td style="text-align: center">
                <span style="">
                    <%= Model.ChiTietDonDatHangModel.GetModel.LstObjModel[i].SoLuong.Value %></span>
            </td>
            <td style="text-align: center">
                <span style="">
                    <%= string.Format("{0:0,0}", Model.ChiTietDonDatHangModel.GetModel.LstObjModel[i].Gia.Value) %>
                    Đ</span>
            </td>
        </tr>
        <% } %>
</table>
<% } %>
<% } %>